package com.itheima.health.mq;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Component
public class SmsConsumer {

    @RabbitListener(queues = "heima-queue")
    public void receive(Map map, Channel channel, Message message) throws IOException {
        //会话唯一ID
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try {
            String telephone = (String) map.get("telephone");
            String code = (String) map.get("code");
            //阿里云发短信
            //SmsUtils.validUserTelephone(telephone, code);
            System.out.println("发短信");
            channel.basicAck(deliveryTag, false);
        } catch (Exception e) {
            channel.basicNack(deliveryTag, false, true);
        }

    }
}
